The Pasteboard namespace provides a complete interface for reading, writing, and observing system pasteboard (clipboard) changes in the Scripting app.
Compared to the deprecated Clipboard API, Pasteboard offers more robust features, including:
onChanged and onRemoved)localOnly and expiration timeNote To allow pasting from other apps, go to: Settings > Scripting > Paste from Other Apps > Allow
PasteboardItemRepresents a pasteboard item.
Each item is a map (Record<UTType, string | UIImage | Data>) where the key is a data type (UTType) and the value can be a string, image, or binary data.
Common types:
public.plain-text → plain textpublic.url → URL stringpublic.jpeg / public.png → image (UIImage)public.data → binary data (Data)Example
hasStrings: Promise<boolean>Checks whether the pasteboard contains text content.
Example
hasImages: Promise<boolean>Checks whether the pasteboard contains images.
Example
hasURLs: Promise<boolean>Checks whether the pasteboard contains URLs.
Example
numberOfItems: Promise<number>Returns the number of items currently stored in the pasteboard.
Example
changeCount: Promise<number>Returns the number of times the pasteboard contents have changed since system startup. This value increases whenever the pasteboard is modified (items added, updated, or removed).
Example
getString(): Promise<string | null>Retrieves the text string of the first pasteboard item.
Example
setString(string: string | null): Promise<void>Sets the text string of the first pasteboard item.
Example
getStrings(): Promise<string[] | null>Retrieves all text strings from the pasteboard.
Example
setStrings(strings: string[] | null): Promise<void>Sets multiple text strings to the pasteboard (each string becomes a separate item).
Example
getURL(): Promise<string | null>Retrieves the first URL string from the pasteboard.
Example
setURL(url: string | null): Promise<void>Sets a URL string as the first pasteboard item.
Example
getURLs(): Promise<string[] | null>Retrieves all URL strings from the pasteboard.
Example
setURLs(urls: string[] | null): Promise<void>Sets multiple URLs to the pasteboard.
Example
getImage(): Promise<UIImage | null>Retrieves the first image (UIImage) from the pasteboard.
Example
setImage(image: UIImage | null): Promise<void>Sets the first pasteboard item to an image.
Example
getImages(): Promise<UIImage[] | null>Retrieves all image objects from the pasteboard.
Example
setImages(images: UIImage[] | null): Promise<void>Sets multiple images to the pasteboard.
Example
addItems(items: Item[]): Promise<void>Appends new items to the existing pasteboard content without clearing it.
Example
setItems(items: Item[], options?: { localOnly?: boolean, expirationDate?: Date }): Promise<void>Replaces the pasteboard contents with new items and applies optional privacy settings.
Parameters
items: An array of pasteboard items.options.localOnly: If true, prevents the pasteboard content from being shared to other devices via Handoff.options.expirationDate: Sets an expiration time after which the system automatically removes the content.Example
getItems(): Promise<Item[] | null>Retrieves all pasteboard items as an array of Pasteboard.Item objects.
Example
onChanged: ((addedKeys: string[]) => void) | null | undefinedCalled when the pasteboard content changes.
The parameter addedKeys is an array of the added representation types (UTType).
Example
onRemoved: ((removedKeys: string[]) => void) | null | undefinedCalled when content is removed from the pasteboard.
The parameter removedKeys is an array of the removed representation types (UTType).
Example
The legacy Clipboard namespace is deprecated and retained only for backward compatibility.
| Deprecated Method | Replacement |
|---|---|
Clipboard.copyText(text: string) |
Pasteboard.setString(text) |
Clipboard.getText() |
Pasteboard.getString() |
Pasteboard API instead of Clipboard.changeCount to detect when pasteboard contents have changed.expirationDate to automatically clear sensitive data after a specific duration.localOnly: true for data that should not sync across devices.hasStrings, hasImages, and hasURLs to check available content types before reading.onChanged and onRemoved callbacks to react in real time to pasteboard updates.